import { defineStore } from 'pinia';
import { ref } from 'vue'

export const useTokenStore = defineStore('token', () => {
  const token = ref(localStorage.getItem('token') || '');

  function getToken() {
    return token.value;
  }

  function setToken(newToken: string) {
    token.value = newToken;
    localStorage.setItem('token', newToken);
  }

  function clearToken() {
    token.value = '';
    localStorage.removeItem('token');
  }
  return { token, getToken, setToken, clearToken };
});